// pages/shezhi/shezhi.js
let  app = getApp(); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wximg: '',
    userName: '',
    canIUse: wx.canIUse('button.open-type.getUser')
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function() {
   

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // console.log(app.globalData.userInfo)
    this.setData({
      wximg: app.globalData.userInfo.wximg,
      userName: app.globalData.userInfo.userName
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let that = this;
    let relation = '1';
    if (wx.getStorageSync('authorities').indexOf("ROLE_ADMIN") > -1) {
      relation = '0';
    }
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    wx.showShareMenu({
      withShareTicket: true
    })

    return {
      title: '柚子课程表',//分享内容
      path: '/pages/index/index?id=' + wx.getStorageSync('open_id') + '&realtion=' + relation,//分享地址
      imageUrl: '../../image/youzi.jpg',//分享图片
      success: function (res) {
        if (res.errMsg == 'shareAppMessage:ok') {//判断分享是否成功
          if (res.shareTickets == undefined) {//判断分享结果是否有群信息
            //分享到好友操作...
          } else {
            //分享到群操作...
            var shareTicket = res.shareTickets[0];
            wx.getShareInfo({
              shareTicket: shareTicket,
              success: function (e) {
                //当前群相关信息
                var encryptedData = e.encryptedData;
                var iv = e.iv;
              }
            })
          }
        }
      }
    }
  },

  personalTap: function() {
    wx.navigateTo({
      url: '../personal/personal'
    })
  },

  versionTap: function(){
    wx.navigateTo({
      url: '../version/version'
    })
  },

  shareTap: function(res){
    var that = this;
    that.onShareAppMessage(res);
  }
})